package com.yiwei.zxp.view;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.adapter.GoodsTypeAdapter;
import com.yiwei.zxp.api.Api;
import com.yiwei.zxp.util.Network;
import com.yiwei.zxp.util.RxLifeUtil;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.util.UI;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class GoodsNumberDilaog extends Dialog {


    @BindView(R.id.txt_tips)
    TextView txtTips;
    @BindView(R.id.btn_close)
    ImageView btnClose;
    @BindView(R.id.edit_num)
    EditText editNum;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    private Context context;


    public GoodsNumberDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public GoodsNumberDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_goods_number);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.BOTTOM;
        mWindow.setAttributes(lp);

    }


    @OnClick({R.id.btn_close, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_close:
                dismiss();
                break;
            case R.id.btn_submit:
                if (TextUtils.isEmpty(UI.toString(editNum))) {
                    ToastUtil.makeText(context, "输入数量");
                    return;
                }
                if (UI.toInteger(editNum) > 100000) {
                    ToastUtil.makeText(context, "最多可以添加100000库存");
                    return;
                }
                if (onChooseListener != null) {
                    onChooseListener.onChooseNumber(UI.toString(editNum));
                }
                dismiss();
                break;
        }
    }


    private OnChooseListener onChooseListener;

    public GoodsNumberDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    public interface OnChooseListener {
        void onChooseNumber(String number);
    }
}
